// import whoami from '@feidao/web/atom/browser/msg/whoami';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import s_get from '@dfeidao/atom-web/storage/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import P04 from './P04';
import P05 from './P05';
import P06 from './P06';

import get from '@dfeidao/atom-web/local/get';
interface Users {
	page_size: number;
	page_no: number;
	dataArray: string[];
	menu_no: string;
	productid: string;
	count: number;
}


export default async function a011(fd: IFeidaoAiBrowserComponent) {
	const page_no = get(fd, 'page_no') as number;
	const page_size = get(fd, 'page_size') as number;
	// const user = await whoami(get_user_info);

	const productid = await s_get('productid');


	const asd = fd.data.node.querySelector<HTMLSelectElement>('#product_clent_type');
	const client_point_id = asd.value;
	const data = await nodejs<Users>('menu/zj-000001/s006', {
		productid, page_no, page_size: get(fd, 'page_size'), client_type: client_point_id
	});
	if (data.count === 0) {
		fd.data.node.querySelector('[data-feidao-presentation="P05"]').innerHTML = '';
		render(fd, '', P06, 'P06', 'inner');
		render(fd, '', P04, 'P04', 'inner');
	} else {
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = '';
		render(fd, data.dataArray, P06, 'P06', 'inner');
		data.page_no = page_no;
		data.page_size = page_size;
		if (data.count <= page_size) {
			fd.data.node.querySelector('[data-feidao-presentation="P05"]').innerHTML = '';
		} else {
			render(fd, data, P05, 'P05', 'inner');
		}
	}
}
